{extend name='table'}

{block name="button"}
<!--{if auth("add")}-->
<button data-modal='{:url("add")}' data-title="{:lang('添加商户')}" class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('添加商户')}</button>
<!--{/if}-->
<!--{if auth("status")}-->
<a data-confirm="确定要禁用这些商户吗？" data-table-id="UserTable" data-action="{:url('status')}" data-rule="id#{id};status#2" class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('批量禁用')}</a>
<!--{/if}-->
<!--{if auth("status")}-->
<a data-confirm="确定要删除这些商户吗？" data-table-id="UserTable" data-action="{:url('remove')}" data-rule="id#{id};status#0" class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('批量删除')}</a>
<!--{/if}-->
{/block}

{block name="content"}
<style type="text/css">
    .layui-tab-card>.layui-tab-title .layui-this {
        background-color: #009988
    }
</style>
<div class="layui-tab layui-tab-card">
    <ul class="layui-tab-title">
        {foreach ['0'=>lang('待入驻'),'1'=>lang('入驻中'),'2'=>lang('已禁用')] as $k=>$v}
        {if isset($type) and $type eq $k}
        <li data-open="{:url('index')}?type={$k}" class="layui-this">{$v}</li>
        {else}
        <li data-open="{:url('index')}?type={$k}">{$v}</li>
        {/if}
        {/foreach}
    </ul>
    <div class="layui-tab-content">
        {include file='index/index_search'}
        <table id="UserTable" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
    </div>
</div>
<script>
    $(function () {
        $('#UserTable').layTable({
            even: true, height: 'full',
            sort: {field: 'status desc,id', type: 'desc'},
            where: {type: '{$type|default="0"}'},
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'username', title: '{:lang("账号")}', minWidth: 100, align: 'center', templet: '<div>{{d.username||"-"}}</div>'},
                {field: 'merchname', title: '{:lang("名称")}', minWidth: 100, align: 'center', templet: '<div>{{d.merchname||"-"}}</div>'},
                {field: 'merchno', title: '{:lang("编码")}', align: 'center', minWidth: 100, sort: true},
                {
                    field: 'logo', title: '{:lang("LOGO")}', width: 80, align: 'center', templet: function (d) {
                        if (!d.logo) return '-';
                        return layui.laytpl('<div class="headimg headimg-ss shadow-inset margin-0" data-tips-image data-tips-hover data-lazy-src="https://qny.soo58.com/{{d.logo}}"></div>').render(d);
                    }
                },
                {
                    field: 'type', title: '{:lang("类型")}', width: 80, align: 'center', sort: true, templet: function (d) {
                        if (d.type == 0) return '供货商';
                        if (d.type == 1) return '业务员';
                    }
                },
                {field: 'realname', title: '{:lang("联系人")}', align: 'center', minWidth: 80},
                {field: 'mobile', title: '{:lang("联系电话")}', align: 'center', minWidth: 80},
                {toolbar: '#toolbar', title: '{:lang("操作")}', align: 'center', minWidth: 200, fixed: 'right'}
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('status')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#UserTable').trigger('reload');
                }); else {
                    $('#UserTable').trigger('reload')
                }
                return false;
            }, false);
        });
    });
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('已激活')}|{:lang('已禁用')}" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status=1 ? '<b class="color-green">{:lang("已激活")}</b>' : '<b class="color-red">{:lang("已禁用")}</b>'}}
    <!--{/if}-->
</script>

<script type="text/html" id="toolbar">
    <!--{if auth("edit")}-->
    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="{:lang('编辑用户')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    <!--{/if}-->
    <!--{if auth("pass")}-->
    <a class="layui-btn layui-btn-sm layui-btn-normal" data-title="{:lang('设置密码')}" data-modal='{:url("pass")}?id={{d.id}}'>{:lang('密 码')}</a>
    <!--{/if}-->
    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="{:lang('确定要永久删除吗？')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    <!--{/if}-->
</script>
{/block}
